import request from '@/config/axios'

// 获取食谱列表
export const getRecipes = (params) => {
  return request({
    url: '/api/recipe/recipes',
    method: 'get',
    params
  })
}

// 获取食谱详情
export const getRecipeDetail = (id) => {
  return request({
    url: `/api/recipe/recipes/${id}`,
    method: 'get'
  })
}

// 搜索食谱
export const searchRecipes = (params) => {
  return request({
    url: '/api/recipe/recipes/search',
    method: 'get',
    params
  })
}

// 添加收藏
export const addFavorite = (recipeId, params) => {
  return request({
    url: `/api/recipe/favorites/${recipeId}`,
    method: 'post',
    params
  })
}

// 取消收藏
export const removeFavorite = (recipeId, params) => {
  return request({
    url: `/api/recipe/favorites/${recipeId}`,
    method: 'delete',
    params
  })
}

// 获取收藏列表
export const getFavorites = (params) => {
  return request({
    url: '/api/recipe/favorites',
    method: 'get',
    params
  })
}

// 检查是否已收藏
export const checkFavorite = (recipeId) => {
  return request({
    url: `/api/recipe/favorites/check/${recipeId}`,
    method: 'get'
  })
}

// 添加食谱
export const addRecipe = (data) => {
  return request({
    url: '/api/recipe',
    method: 'post',
    data
  })
}

// 上传食谱图片
export const uploadRecipeImage = (recipeId, data) => {
  return request({
    url: `/api/recipe/image/${recipeId}`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}

// 删除食谱
export const deleteRecipe = (recipeId) => {
  return request({
    url: `/api/recipe/${recipeId}`,
    method: 'delete'
  })
}

// 更新食谱
export const updateRecipe = (recipeId, data) => {
  return request({
    url: `/api/recipe/${recipeId}`,
    method: 'put',
    data
  })
} 